from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import SPUSpecification, SPU
from apps.meiduo_admin.serializers import SPUSpecsSerializer, SimpleSPUSerializer
from apps.meiduo_admin.utils import CurPagination


class SpecsView(ModelViewSet):

    permission_classes = [IsAdminUser]
    queryset = SPUSpecification.objects.all().order_by('spu_id')
    serializer_class = SPUSpecsSerializer
    pagination_class = CurPagination

    def simple(self, request):
        spus = SPU.objects.values('id', 'name')
        ser = SimpleSPUSerializer(spus, many=True)
        return Response(ser.data)
